import { Component } from '@angular/core';
import { Location } from '@angular/common';
import { Router } from '@angular/router';
import { ActivatedRoute } from '@angular/router';

import { Observable } from 'rxjs/Rx';
import 'rxjs/add/operator/map';
import 'rxjs/add/operator/switchMap';
import { ParamMap } from '@angular/router';


@Component({
    selector : 'c',
    template : "路由定义的数据{{title}}<input type='button' value='jumptoa' (click)='a()' /><input type='button' value='jumptob' (click)='b()' />",
    providers : [Location]
})
export class CComponent{
     constructor(private location:Location, private router:Router, private route:ActivatedRoute){
         console.log('=================');
         console.log(router.routerState);
         console.log('========22===========');
         console.log(route.data);
         console.log('=========3===========');
         const id: Observable<string> = route.params.map(p => p.id);
         id.subscribe(id=>console.log(id));    
         console.log('================4===============');
         this.route.paramMap
            .switchMap((params: ParamMap) => params.get('id')).subscribe(id=>console.log(id));     
     }
     a(){
         this.location.back();
     }
     b(){
         this.router.navigate(['/b', {id:1,name:''}]);
     }
}